<template>
  <section class="login-container">
    <div class="panel">
      <div class="left-panel">
        <div class="left-panel-bg">
          <div class="content">
            <h2 class="welcome">Welcome</h2>
            <h3 class="system-name">欢迎使用</h3>
            <h3 class="system-name strong">项目管理</h3>
          </div>
        </div>
      </div>

      <div class="right-panel">
        <!-- <img class="login-logo" src="@/assets/images/login-logo.png" alt="" /> -->
        <div class="logo">登录</div>
        <div class="login-form">
          <el-form
            :model="form"
            :rules="rules"
            label-position="top"
            ref="rrr"
            label-width="0"
          >
            <el-form-item prop="username">
              <el-input
                v-model="form.username"
                placeholder="请输入账号"
                clearable
              >
                <i slot="prefix" class="iconfont icon-zhanghao" />
              </el-input>
            </el-form-item>
            <el-form-item
              prop="password"
              @keyup.enter.native="submitForm('rrr')"
            >
              <el-input
                v-model="form.password"
                placeholder="请输入密码"
                type="password"
                clearable
              >
                <i slot="prefix" class="iconfont icon-mima" />
              </el-input>
            </el-form-item>
            <el-button
              :loading="loading"
              type="primary"
              class="btn-login"
              @click="submitForm('rrr')"
              >登录</el-button
            >
          </el-form>
        </div>
      </div>
    </div>
  </section>
</template>

<script>
import _cryptojs from "crypto-js";
import HttpClient from "../common/HttpClient";
import api from "@/common/api/dictionary.js";
export default {
  data() {
    return {
      loading: false,
      form: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "用户名不能为空", trigger: "blur" },
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    async submitForm(formName) {
      try {
        this.loading = true;
        await this.$refs[formName].validate();
        await HttpClient.loginAsync(
          this.form.username,
          _cryptojs.MD5(this.form.password).toString()
        );
        // await this.getHolidays();
        // await this.getLastUpdate();
        this.$router.push("/");
      } catch (error) {
        if (error == false) return;
        this.$message({
          message: JSON.stringify(error),
          type: "error",
        });
      } finally {
        this.loading = false;
      }
    },

    // async getHolidays() {
    //     const result = await api.getListAsync({
    //         key: "holidays",
    //     });
    //     console.log(result.data, "data");
    //     sessionStorage.holidays = result.data[0].value.split(",");
    // },

    // async getLastUpdate() {
    //     const result = await api.getListAsync({
    //         key: "updateDate",
    //     });
    //     console.log(result.data, "data");
    //     sessionStorage.updateDate = result.data[0].value;
    // },
    // resetForm(formName) {
    //     this.$refs[formName].resetFields();
    // },
  },
};
</script>

<style lang="scss">
.login-container {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f4f4f4;

  .panel {
    display: flex;
    width: 1000px;
    height: 560px;
    border-radius: 10px;
    box-shadow: 0 0.5rem 1.2rem #999;
    overflow: hidden;

    .left-panel {
      flex: 1.2;
      background: linear-gradient(180deg, #51b0ff, #2878ff);

      .left-panel-bg {
        width: 100%;
        height: 100%;
        background: url("../assets/images/bg3.svg") no-repeat;
        background-position: 1% 90%;
        background-size: 70%;
        transform: scale(0.8);
      }

      .content {
        width: 420px;
        line-height: 1.2;

        h2 {
          font-size: 50px;
          margin-bottom: 10px;
          color: white;
          font-family: "optima";
        }

        h3 {
          font-size: 40px;
          color: white;
          font-family: "隶书";
        }

        .strong {
          font-size: 45px;
        }
      }
    }

    .right-panel {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      background: white;
      position: relative;
      .logo {
        position: absolute;
        top: 20%;
        font-size: 2.5rem;
        font-weight: 700;
      }

      .login-logo {
        position: absolute;
        transform: scale(0.2);
        top: 1%;
      }

      .login-form {
        width: 300px;

        .iconfont {
          margin-left: 4px;
        }

        .btn-login {
          width: 100%;
          letter-spacing: 1rem;
          font-size: 1.2rem;
        }
      }
    }
  }
}
</style>
